home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / file-tra / fsp-2.7 / fsp-2 / fsp / clients / fput.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-23  |  1.6 KB  |  68 lines

  1.     /*********************************************************************\
  2.     *  Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu)   *
  3.     *                                                                     *
  4.     *  You may copy or modify this file in any manner you wish, provided  *
  5.     *  that this notice is always included, and that you hold the author  *
  6.     *  harmless for any loss or damage resulting from the installation or *
  7.     *  use of this software.                                              *
  8.     \*********************************************************************/
  9.  
  10. #include "tweak.h"
  11. #include "client_def.h"
  12. #include "c_extern.h"
  13.  
  14. static int put_file PROTO1(char *, path)
  15. {
  16.   struct stat sb;
  17.   char *name, *t2;
  18.   FILE *fp;
  19.   
  20.   if(stat(path,&sb) != 0) {
  21.     perror(path);
  22.     return;
  23.   }
  24.   if(!(S_ISREG(sb.st_mode))) {
  25.     fprintf(stderr,"%s: not a file\n",path);
  26.     return;
  27.   }
  28.   
  29.   for(name = t2 = path; *t2; t2++)
  30.     if(*t2 == '/') name = t2 + 1;
  31.   
  32.   if(fp = fopen(path,"r")) {
  33.     util_upload(name,fp);
  34.     fclose(fp);
  35.   } else fprintf(stderr,"Cannot read %s\n",path);
  36. }
  37.  
  38. int main PROTO3(int, argc, char **, argv, char **, envp)
  39. {
  40.   char n[1024];
  41.   int prompt;
  42.   
  43.   env_client();
  44.   if (strcmp(env_local_dir,".") && chdir(env_local_dir)) {
  45.     perror("chdir");
  46.     exit(1);
  47.   }
  48.   
  49.   if(argc > 1)
  50.     while(*++argv) put_file(*argv);
  51.   else {
  52.     prompt = isatty(0);
  53.     while(1) {
  54.       if(prompt) {
  55.     fputs("fput: ",stdout);
  56.     fflush(stdout);
  57.       }
  58.       if(!gets(n)) break;
  59.       if(!*n) continue;
  60.       put_file(n);
  61.     }
  62.   }
  63.   
  64.   client_done();
  65.   
  66.   exit(0);
  67. }
  68.